import {baseEffects, baseReducers, baseState} from "../../../../models/baseModel";
import moment from "moment";
import $$ from "utils/index";

export default {
  namespace: 'qualityData',

  state: {
    ...baseState,
  },

  reducers: {
    ...baseReducers
  },

  effects: {

    ...baseEffects,

    * getPageInfo({payload}, {call, put}) {

      const p = {
        ...payload,
        baseUrl: getBaseUrl(),
        process: (records) => {
          return records.map(record => {
            return {
              ...record,
              diff: Math.floor(Math.abs(record.value - record.agv) * 100) / 100,
              value: Math.floor(record.value * 100) / 100,
              time: moment(record.time).format('YYYY-MM-DD HH:mm:ss'),
            };
          });
        }
      }

      yield put({
        type: 'baseGetPageInfo',
        payload: p
      });
    },

  }

}

function getBaseUrl() {
  return "/quality-data";
}
